package com.ruoyi.hsj.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.hsj.mapper.ProjectStepMapper;
import com.ruoyi.hsj.domain.ProjectStep;
import com.ruoyi.hsj.service.IProjectStepService;

/**
 * 项目实施流程Service业务层处理
 * 
 * @author hsj
 * @date 2024-11-27
 */
@Service
public class ProjectStepServiceImpl implements IProjectStepService 
{
    @Autowired
    private ProjectStepMapper projectStepMapper;

    /**
     * 查询项目实施流程
     * 
     * @param id 项目实施流程主键
     * @return 项目实施流程
     */
    @Override
    public ProjectStep selectProjectStepById(Long id)
    {
        return projectStepMapper.selectProjectStepById(id);
    }

    /**
     * 查询项目实施流程列表
     * 
     * @param projectStep 项目实施流程
     * @return 项目实施流程
     */
    @Override
    public List<ProjectStep> selectProjectStepList(ProjectStep projectStep)
    {
        return projectStepMapper.selectProjectStepList(projectStep);
    }

    /**
     * 新增项目实施流程
     * 
     * @param projectStep 项目实施流程
     * @return 结果
     */
    @Override
    public int insertProjectStep(ProjectStep projectStep)
    {
        projectStep.setCreateTime(DateUtils.getNowDate());
        String minMoney = projectStep.getMinMoney();
        String maxMoney = projectStep.getMaxMoney();
        String range = "X";
        if (StringUtils.isNoneBlank(minMoney)){
            range = minMoney + " <= " + range ;
        }

        if (StringUtils.isNoneBlank(maxMoney)){
            range = range + " <= " + maxMoney;
        }

        if (StringUtils.isNoneBlank(minMoney) || StringUtils.isNoneBlank(maxMoney)){
            projectStep.setRangeMoney(range);
        }


        return projectStepMapper.insertProjectStep(projectStep);
    }

    /**
     * 修改项目实施流程
     * 
     * @param projectStep 项目实施流程
     * @return 结果
     */
    @Override
    public int updateProjectStep(ProjectStep projectStep)
    {
        String minMoney = projectStep.getMinMoney();
        String maxMoney = projectStep.getMaxMoney();
        String range = "X";
        if (StringUtils.isNoneBlank(minMoney)){
            range = minMoney + " <= " + range ;
        }

        if (StringUtils.isNoneBlank(maxMoney)){
            range = range + " <= " + maxMoney;
        }

        if (StringUtils.isNoneBlank(minMoney) || StringUtils.isNoneBlank(maxMoney)){
            projectStep.setRangeMoney(range);
        }

        projectStep.setUpdateTime(DateUtils.getNowDate());
        return projectStepMapper.updateProjectStep(projectStep);
    }

    /**
     * 批量删除项目实施流程
     * 
     * @param ids 需要删除的项目实施流程主键
     * @return 结果
     */
    @Override
    public int deleteProjectStepByIds(Long[] ids)
    {
        return projectStepMapper.deleteProjectStepByIds(ids);
    }

    /**
     * 删除项目实施流程信息
     * 
     * @param id 项目实施流程主键
     * @return 结果
     */
    @Override
    public int deleteProjectStepById(Long id)
    {
        return projectStepMapper.deleteProjectStepById(id);
    }
}
